package com.ruoyi.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.SysPost;
import com.ruoyi.mapper.SysPostMapper;

@Service
public class SysPostService {

	@Autowired
	private SysPostMapper sysPostMapper;
	
	public List<SysPost> selectPostList(SysPost post) {
		return sysPostMapper.selectPostList(post);
	}

	public boolean checkPostNameUnique(SysPost post) {
		Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
		SysPost info = sysPostMapper.checkPostNameUnique(post.getPostName());
		if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
			return UserConstants.NOT_UNIQUE;
		}
		return UserConstants.UNIQUE;
	}

	public boolean checkPostCodeUnique(SysPost post) {
		Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
		SysPost info = sysPostMapper.checkPostCodeUnique(post.getPostCode());
		if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
			return UserConstants.NOT_UNIQUE;
		}
		return UserConstants.UNIQUE;
	}

	public int insertPost(SysPost post) {
		return sysPostMapper.insertPost(post);
	}

	public int updatePost(SysPost post) {
		return sysPostMapper.updatePost(post);
	}

	public SysPost selectPostById(Long postId) {
		return sysPostMapper.selectPostById(postId);
	}

	public int deletePostById(Long postId) {
		return sysPostMapper.deletePostById(postId);
	}

	public List<SysPost> selectPostAll() {
		return sysPostMapper.selectPostAll();
	}

	public List<Long> selectPostListByUserId(Long userId) {
		return sysPostMapper.selectPostListByUserId(userId);
	}

}
